package com.example.hospital.service.impl;

import com.example.hospital.exception.PositionServiceException;
import com.example.hospital.mapper.PositionMapper;
import com.example.hospital.pojo.Position;
import com.example.hospital.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PositionServiceImpl implements PositionService {

    @Autowired
    private PositionMapper positionMapper;

    // 添加职位
    @Override
    public void addPosition(Position position) {
        if(positionMapper.findByName(position).getName().equals(position.getName())){
            throw new PositionServiceException("The position already exists!");
        }
        positionMapper.insertPosition(position);
    }

    // 获取所有职位
    @Override
    public List<Position> getAllPositions() {
        return positionMapper.findAll();
    }

    // 根据ID获取职位
    @Override
    public Position getPositionById(Integer id) {
        return positionMapper.findById(id);
    }

    // 更新职位
    @Override
    public void updatePosition(Position position) {
        positionMapper.updatePosition(position);
    }

    // 删除职位
    @Override
    public void deletePosition(Integer id) {
        positionMapper.deletePosition(id);
    }
}
